package com.ruoyi.system.controller;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.domain.Activity;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.service.IActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * 商家活动，存储商家发布的霸王餐活动信息Controller
 *
 * @author ruoyi
 * date  2025-06-26
 */
@RestController
@RequestMapping("/activity")
public class ActivityController extends BaseController {
    @Autowired
    private IActivityService activityService;

    /**
     * 查询商家活动，存储商家发布的霸王餐活动信息列表
     */
    @RequiresPermissions("system:activity:list")
    @GetMapping("/list")
    public TableDataInfo list(Activity activity)
    {
        startPage();
        List<Activity> list = activityService.selectActivityList(activity);
        return getDataTable(list);
    }

    /**
     * 导出商家活动，存储商家发布的霸王餐活动信息列表
     */
    @RequiresPermissions("system:activity:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Activity activity)
    {
        List<Activity> list = activityService.selectActivityList(activity);
        ExcelUtil<Activity> util = new ExcelUtil<Activity>(Activity.class);
        util.exportExcel(response, list, "商家活动，存储商家发布的霸王餐活动信息数据");
    }

    /**
     * 获取商家活动，存储商家发布的霸王餐活动信息详细信息
     */
    @RequiresPermissions("system:activity:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(activityService.selectActivityById(id));
    }

    /**
     * 新增商家活动，存储商家发布的霸王餐活动信息
     */
    @RequiresPermissions("system:activity:add")
    @PostMapping
    public AjaxResult add(@RequestBody Activity activity)
    {
        return toAjax(activityService.insertActivity(activity));
    }

    /**
     * 修改商家活动，存储商家发布的霸王餐活动信息
     */
    @RequiresPermissions("system:activity:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody Activity activity)
    {
        return toAjax(activityService.updateActivity(activity));
    }

    /**
     * 删除商家活动，存储商家发布的霸王餐活动信息
     */
    @RequiresPermissions("system:activity:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(activityService.deleteActivityByIds(ids));
    }
}
